<?php require("../globals.inc"); $mikron->Page->StartBody();?>
<?php require_once('menu.inc'); ?>

    <?php
        if(isset($_REQUEST['clearrecycle']))
        {
            $result = mysql_query("SELECT * FROM ENTITIES");
            if(!mysql_errno())
            {
                while($row = mysql_fetch_object($result))
                {
                    $name = $row->name;
                    mysql_query("DELETE FROM $name WHERE `mikron_state` = 1");
                }
                echo "<p>Корзина успешно очищена.</p>";
            }
        }
    ?>
    
    <div class="insideblock">

        <table cellspacing="0" cellpadding="3" width="100%">
        <tr><td valign="top" width="10%">
            <table cellspacing="0" cellpadding="0">
            <?php
                $recycleElementsCount = 0;
                $result = mysql_query('SELECT * FROM ENTITIES ORDER BY `name`');
                if(!mysql_errno())
                {                
                    while($row = mysql_fetch_object($result))
                    {
                        $id = $row->id;
                        $name = $row->name;
                        $e = new $name;
                        $description = $e->description();
                        $count = 0;
                        $r = mysql_query("SELECT COUNT(*) cnt FROM $name WHERE `mikron_state` = 1");
                        $count = mysql_result($r, 0, "cnt");
                        $link = "recycle.php?entityname=".$name;
                        if(basename($_SERVER['REQUEST_URI']) == $link)
                        {
                        ?>
                        <tr style="background-color: #1a1a1a;">
                        <?php } else { ?><tr><?php } ?>
                        <td nowrap="nowrap" style="line-height: 1.5em;"><?php
                        if($count > 0)
                        {
                            ?><a href="<?php echo $link; ?>"><?php echo $name; ?></a> <?php echo $description; ?><?php
                        }
                        else
                        {
                           ?><font style="color: #7c8b0c;"><?php echo $name; ?></font> <?php echo $description; ?><?php                        
                        }
                        ?></td><td style="text-align: right; padding-left: 1em;"><?php
                        echo $count?$count:"<font color=\"#4a4a4a\">—</font>";
                        ?>
                        </td>
                        </tr>
                        <?php
                        $recycleElementsCount++;
                    }
                }
            ?>
            <tr>
                <td colspan="2">               
                    <?php  if($recycleElementsCount) { ?>
                    <a href="?clearrecycle">Очистить корзину</a>
                    <?php } else { echo 'Корзина пуста.';} ?>
                </td>
            </tr>
           
            </table>
        </td>
        <td valign="top" bgcolor="#1a1a1a">
            <?php
                if(isset($_REQUEST['entityname']))
                {
                    $entityname = $_REQUEST['entityname'];
                    $items = $mikron->EntityManager->QueryDeleted($entityname);
                    if(count($items) < 1)
                    {
                        ?>В корзине нет сущностей типа <?php echo $entityname.".";
                    }
                    else
                    {
                        $mikron->EntityManager->ShowList($items, false, false, true);
                    }
                }
            ?>
        </td>
        </tr>
        </table>

    </div>

<?php $mikron->Page->EndBody(); ?>